package com.ssm.student.controller;

import com.ssm.student.model.Role;
import com.ssm.student.service.RoleService;
import com.ssm.student.service.impl.RoleServiceImpl;
import com.ssm.student.tool.ResponseMessage;
import com.ssm.student.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/*对外提供数据接口*/
@Api(tags="role")
@RestController
public class RoleController {

    @Autowired
    private RoleServiceImpl roleService;
    @ApiOperation(value = "角色添加方法")
   @RequestMapping(value = "/addRole",method = RequestMethod.GET)
    public int AddRole(Role role){
        //传入数据的判断
        int IsAdd=0;
        //（1）角色实体不能为空
        if(role!=null){
            //（2）角色名称不能为空
            if(role.getRolename()!=null){
                //(3)添加角色数据
                roleService.insertRole(role);
            }
        }
        return IsAdd;
    }

    public ResponseMessage add(Role role){
        int IsAdd=0;
        //（1）角色实体不能为空
        if(role!=null){
            //（2）角色名称不能为空
            if(role.getRolename()!=null){
                //(3)添加角色数据
               IsAdd= roleService.insertRole(role);
               if(IsAdd==1){
                   return Result.success("保存成功");
               }else if(IsAdd==-1){
                   return Result.error("角色重复");
               }else{
                   return Result.error("保存失败");
               }
            }
        }
      return Result.error("保存失败");

    }


}
